package com.wuyan.warriorsoffate.ui.page

import android.util.Log
import androidx.compose.animation.*
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import com.wuyan.warriorsoffate.data.NesViewModel
import com.wuyan.warriorsoffate.data.ShopNames
import com.wuyan.warriorsoffate.ui.theme.WeTheme
import com.wuyan.warriorsoffate.ui.view.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import kotlin.math.min

@ExperimentalAnimationApi
@Composable
fun SundryPage(nes:NesViewModel,modifier: Modifier=Modifier){
    val dialogType= remember {
        mutableStateOf(DialogType.NONE)
    }
    val scope= rememberCoroutineScope()
    val state= LazyListState(0,0)
    val scrollState= rememberScrollState()
    val shopId= remember {
        mutableStateOf(0)
    }
    Column(horizontalAlignment = Alignment.CenterHorizontally) {
        StaggeredGrid(padding= WeTheme.weDp.marginMedium) {
            ButtonItem(text = "MSP"){
                dialogType.value= DialogType.MSP
            }
            InfiniteTransitionSizeAnimate(){
                WeLabel(bgColor = WeTheme.colors.text){
                    Row(verticalAlignment = Alignment.CenterVertically) {
                        WeText(text = "是否穿墙", color = WeTheme.colors.onText)
                        Checkbox(nes.isWall, onCheckedChange = {
                            nes.isWall=! nes.isWall
                        })
                    }
                }
            }
            WeLabel(bgColor = WeTheme.colors.text){
                Row(verticalAlignment = Alignment.CenterVertically) {
                    WeText(text = "护身烟步数", color = WeTheme.colors.onText)
                    TextFieldHexOrDex255(isHex = nes.state.isHex, dec = nes.mistNum)
                }
            }
        }
        Column(modifier = Modifier
            .verticalScroll(scrollState)
            .padding(WeTheme.weDp.paddingMedium)
            .fillMaxWidth()
            .weight(1.0f),horizontalAlignment = Alignment.CenterHorizontally) {
            Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.padding(WeTheme.weDp.marginSmall)){
                WeLabel(text = "初始三杰", modifier = Modifier)
                WeLabel(){
                    StaggeredGrid(modifier = Modifier.wrapContentSize(), itemAlign = StaggeredGridItemAlign.Start) {
                        for (i in nes.initPersons.indices) {
                            Row(verticalAlignment = Alignment.CenterVertically) {
                                WeText(text = nes.persons[0xa8 + i].name + ":")
                                SelectPerson(nes.initPersons[i], nes, state, scope)
                            }
                        }
                    }
                }
            }
            Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.padding(WeTheme.weDp.marginSmall)){
                WeLabel(text = "初始三杰携带物品", modifier = Modifier)
                WeLabel(){
                    Row() {
                        for (index in nes.initPersons.indices){
                            Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.weight(0.5f)) {
                                WeText(text = nes.persons[nes.initPersons[index].value].name)
                                StaggeredGrid(modifier = Modifier.wrapContentSize(), itemAlign = StaggeredGridItemAlign.Start) {
                                    for (i in nes.initPersonsProp[index].indices){
                                        SelectWuping(personAddress = nes.initPersonsProp[index][i], nes = nes)
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.padding(WeTheme.weDp.marginSmall)){
                WeLabel(text = "替换人物", modifier = Modifier)
                WeLabel(){
                    StaggeredGrid(modifier = Modifier.wrapContentSize(), itemAlign = StaggeredGridItemAlign.Start) {
                        for (i in nes.replacePersons.indices){
                            Row(verticalAlignment = Alignment.CenterVertically) {
                                WeText(text = nes.persons[nes.replacePersonsInit[i]].name)
                                SelectPerson(nes.replacePersons[i],nes,state,scope)
                            }
                        }
                    }
                }
            }
            Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.padding(WeTheme.weDp.marginSmall)){
                WeLabel(text = "不能离队武将", modifier = Modifier)
                WeLabel(){
                    StaggeredGrid(modifier = Modifier.wrapContentSize(), itemAlign = StaggeredGridItemAlign.Start) {
                        for (i in nes.notLeavePersons.indices){
                            Row(verticalAlignment = Alignment.CenterVertically) {
                                SelectPerson(nes.notLeavePersons[i],nes,state,scope)
                            }
                        }
                    }
                }
            }
            Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.padding(WeTheme.weDp.marginSmall)){
                WeLabel(text = "不能解雇武将", modifier = Modifier)
                WeLabel(){
                    StaggeredGrid(modifier = Modifier.wrapContentSize(), itemAlign = StaggeredGridItemAlign.Start) {
                        for (i in nes.notFirePersons.indices){
                            Row(verticalAlignment = Alignment.CenterVertically) {
                                SelectPerson(nes.notFirePersons[i],nes,state,scope)
                            }
                        }
                    }
                }
            }
            Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.padding(WeTheme.weDp.marginSmall)){
                WeLabel(text = "不可暗杀武将", modifier = Modifier)
                WeLabel(){
                    StaggeredGrid(modifier = Modifier.wrapContentSize(), itemAlign = StaggeredGridItemAlign.Start) {
                        for (i in nes.notKillPersons.indices){
                            Row(verticalAlignment = Alignment.CenterVertically) {
                                SelectPerson(nes.notKillPersons[i],nes,state,scope)
                            }
                        }
                    }
                }
            }
            Column(horizontalAlignment = Alignment.CenterHorizontally,modifier = Modifier.padding(WeTheme.weDp.marginSmall)){
                WeButton(text = nes.shops[shopId.value].name, modifier = Modifier, onClick = {
                    dialogType.value= DialogType.ShopNameList
                })
                WeLabel(){
                    Row() {
                        Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.weight(0.5f)) {
                            WeText(text = "武器店")
                            StaggeredGrid(modifier = Modifier.wrapContentSize(), itemAlign = StaggeredGridItemAlign.Start) {
                                val weapon=nes.shops[shopId.value].weaponIds
                                for (i in weapon.indices){
                                    SelectWeapon(personAddress = weapon[i], nes = nes)
                                }
                            }
                        }
                        Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.weight(0.5f)) {
                            WeText(text = "道具店")
                            StaggeredGrid(modifier = Modifier.wrapContentSize(), itemAlign = StaggeredGridItemAlign.Start) {
                                val prop=nes.shops[shopId.value].propIds
                                for (i in prop.indices){
                                    SelectProp(personAddress = prop[i], nes = nes)
                                }
                            }
                        }
                    }
                }
            }
            Column(horizontalAlignment = Alignment.CenterHorizontally,
                modifier = Modifier
                    .align(Alignment.CenterHorizontally)
                    .background(
                        color = WeTheme.colors.bg,
                        shape = RoundedCornerShape(WeTheme.weDp.paddingSmall)
                    )
                    .padding(WeTheme.weDp.paddingSmall)){
                WeLabel(text = "升级经验值", modifier = Modifier)
                WeLabel(){
                    Column(horizontalAlignment = Alignment.CenterHorizontally) {
                        WeButton(onClick = {
                            dialogType.value= DialogType.ArithmeticProgression
                        }, text = "通过等差数列设置")
                        StaggeredGrid(modifier = Modifier.wrapContentSize()) {
                            for (i in nes.dengJis.indices){
                                Row(verticalAlignment = Alignment.CenterVertically) {
                                    WeText(text = "${(i+1).toString(if (nes.state.isHex.value) 16 else 10)}级:")
                                    TextFieldHexOrDex16777216(isHex = nes.state.isHex, dec = nes.dengJis[i].value, onChange = {
                                        Log.e("person","$i 值变换$it")
                                        nes.dengJis[i].value=it
                                    })
                                }
                            }
                        }
                    }

                }
            }
        }
        when(dialogType.value){
            DialogType.NONE->{}
            DialogType.MSP->{
                WeDialog(title = "MSP随机升级值",nes,dialogType) {
                    StaggeredGrid(padding= WeTheme.weDp.marginMedium,
                        itemAlign = StaggeredGridItemAlign.Start) {
                        for (i in nes.msps.indices){
                            WeLabel(bgColor = WeTheme.colors.text){
                                TextFieldHexOrDex255(nes.state.isHex,nes.msps[i])
                            }
                        }
                    }
                }
            }
            DialogType.ShopNameList->{
                WeDialog(title = "城市选择",nes,dialogType) {
                    StaggeredGrid(padding= WeTheme.weDp.marginMedium,
                        itemAlign = StaggeredGridItemAlign.Start) {
                        for (i in ShopNames.indices){
                            WeButton(onClick = {
                                shopId.value=i
                            }, text = ShopNames[i])
                        }
                    }
                }
            }
            DialogType.ArithmeticProgression->{
                val initV= remember {
                    mutableStateOf(nes.dengJis[0].value)
                }
                val initAdd= remember {
                    mutableStateOf(0)
                }
                WeDialog(title = "等差形式批量设置经验值",nes,dialogType) {
                    Column(modifier = Modifier
                        .padding(WeTheme.weDp.paddingMedium)
                        .fillMaxWidth()) {
                        Row(modifier = Modifier.padding(WeTheme.weDp.paddingSmall)) {
                            WeText(text = "等级1经验值：")
                            TextFieldHex16777216(dec = initV.value, change ={
                                initV.value=it
                            } )
                        }
                        Row(modifier = Modifier.padding(WeTheme.weDp.paddingSmall)) {
                            WeText(text = "每次累加值：")
                            TextFieldHex16777216(dec = initAdd.value, change ={
                                initAdd.value=it
                            } )
                        }
                        WeButton(onClick = {
                           for (i in nes.dengJis.indices){
                               val temp= min(0xffffff,initV.value+i*initAdd.value)
                               nes.dengJis[i].value=temp
                           }
                            dialogType.value=DialogType.NONE
                        }, text = "设置", modifier = Modifier.align(Alignment.CenterHorizontally))
                    }
                }
            }
        }
    }
    
}
@Composable
fun ButtonItem(text:String,onClick:()->Unit){
    InfiniteTransitionSizeAnimate(){
        WeButton(text=text ,onClick=onClick)
    }
}
enum class DialogType{
    NONE,
    MSP,
    ShopNameList,
    ArithmeticProgression,
}
@Composable
fun WeDialog(
    title:String,
    nes:NesViewModel,
    dialogType:MutableState<DialogType> = mutableStateOf(DialogType.NONE),
    onDismissRequest: () -> Unit={dialogType.value= DialogType.NONE},
    properties: DialogProperties = DialogProperties(),
    modifier: Modifier=Modifier,
    content: @Composable () -> Unit
){
    Dialog(onDismissRequest, properties) {
        Column(modifier = modifier
            .background(
                WeTheme.colors.bg,
                shape = RoundedCornerShape(WeTheme.weDp.paddingSmall)
            )
            .wrapContentSize()){
            Box(modifier = Modifier
                .fillMaxWidth()
                .align(Alignment.CenterHorizontally)) {
                WeText(text = if (nes.state.isHex.value) "HEX" else "DEC",
                    textAlign = TextAlign.Center,
                    modifier = Modifier
                        .align(Alignment.CenterStart)
                        .padding(WeTheme.weDp.paddingSmall)
                        .align(Alignment.CenterStart)
                        .border(1.dp, color = WeTheme.colors.text, shape = WeTheme.shapes.small)
                        .padding(WeTheme.weDp.paddingSmall)
                        .clickable {
                            nes.state.isHex.value = !nes.state.isHex.value
                        })
                WeText(text = title,modifier = Modifier.align(Alignment.Center),fontSize = WeTheme.typography.body1.fontSize*1.2)
                WeText(text = "关闭",
                    textAlign = TextAlign.Center,
                    modifier = Modifier
                        .padding(WeTheme.weDp.paddingSmall)
                        .align(Alignment.CenterEnd)
                        .border(1.dp, color = WeTheme.colors.text, shape = WeTheme.shapes.small)
                        .padding(WeTheme.weDp.paddingSmall)
                        .clickable {
                            onDismissRequest()
                        })
            }
            content()
        }
    }
}

@ExperimentalAnimationApi
@Composable
fun SelectPerson(personAddress:MutableState<Int>,nes:NesViewModel,state: LazyListState,scope:CoroutineScope){
    val isSelectDialog= remember {
        mutableStateOf(false)
    }
    val ids: SnapshotStateList<Int> = remember {
        mutableStateListOf()
    }
    WeButton(text = if (personAddress.value!=0) nes.persons[personAddress.value].name else "无", onClick = {
        isSelectDialog.value=true
    })
    if (isSelectDialog.value){
        WeDialog(title = "人物选择", nes = nes, onDismissRequest = {
            isSelectDialog.value=false
        }) {
            Column() {
                WeSearchHasList(data = ids, onSearch = {value->
                    val _ids=nes.searchPerson(value)
                    if (_ids.size>0){
                        ids.clear()
                        for (i in _ids){
                            ids.add(i)
                        }
                        scope.launch {
                            state.scrollToItem(ids[0])
                        }
                    }
                }, onSelect = {
                    scope.launch {
                        state.scrollToItem(ids[it])
                    }
                }, modifier = Modifier.padding(WeTheme.weDp.marginMedium))
                WeColumn(state = state){
                    item {
                        WeSurface(modifier = Modifier.clickable {
                            personAddress.value=0
                            isSelectDialog.value=false
                        }) {
                            Row(modifier = Modifier
                                .padding(WeTheme.weDp.marginSmall)
                                .fillMaxWidth()
                                .wrapContentHeight()
                                .shadow(
                                    WeTheme.weDp.marginSmall / 2,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .background(
                                    WeTheme.colors.bg,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .padding(WeTheme.weDp.paddingSmall),
                                verticalAlignment = Alignment.CenterVertically,
                                horizontalArrangement = Arrangement.SpaceBetween) {
                                WeLabel(text = "无", bgColor = WeTheme.colors.label1)
                            }
                        }
                    }
                    items(nes.persons.size-1){index->
                        WeSurface(modifier = Modifier.clickable {
                            personAddress.value=index+1
                            isSelectDialog.value=false
                        }) {
                            Row(modifier = Modifier
                                .padding(WeTheme.weDp.marginSmall)
                                .fillMaxWidth()
                                .wrapContentHeight()
                                .shadow(
                                    WeTheme.weDp.marginSmall / 2,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .background(
                                    WeTheme.colors.bg,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .padding(WeTheme.weDp.paddingSmall),
                                verticalAlignment = Alignment.CenterVertically,
                                horizontalArrangement = Arrangement.SpaceBetween) {
                                WeLabel(text = (index+1).toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label1)
                                WeLabel(text = nes.persons[index+1].name, bgColor = WeTheme.colors.label2)
                                WeLabel(text = "武力："+ nes.persons[index+1].force.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.text)
                                WeLabel(text = "智力："+ nes.persons[index+1].brains.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label1)
                            }
                        }
                    }
                }
            }
        }
    }
}

@ExperimentalAnimationApi
@Composable
fun SelectWeapon(personAddress:MutableState<Int>,nes:NesViewModel){
    val isSelectDialog= remember {
        mutableStateOf(false)
    }
    WeButton(text = if (personAddress.value<0x53) nes.weapon[personAddress.value-0x40].name else nes.defense[personAddress.value-0x59].name, onClick = {
        isSelectDialog.value=true
    })
    if (isSelectDialog.value){
        WeDialog(title = "武器选择", nes = nes, onDismissRequest = {
            isSelectDialog.value=false
        }) {
            Column() {
                WeColumn(){
                    items(nes.weapon.size){index->
                        WeSurface(modifier = Modifier.clickable {
                            personAddress.value=index+0x40
                            isSelectDialog.value=false
                        }) {
                            Row(modifier = Modifier
                                .padding(WeTheme.weDp.marginSmall)
                                .fillMaxWidth()
                                .wrapContentHeight()
                                .shadow(
                                    WeTheme.weDp.marginSmall / 2,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .background(
                                    WeTheme.colors.bg,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .padding(WeTheme.weDp.paddingSmall),
                                verticalAlignment = Alignment.CenterVertically,
                                horizontalArrangement = Arrangement.SpaceBetween) {
                                WeLabel(text = (index+1).toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label1)
                                WeLabel(text = nes.weapon[index].name, bgColor = WeTheme.colors.label2)
                                WeLabel(text = "价格:"+nes.weapon[index].money.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label2)
                                WeLabel(text = "显伤"+nes.weapon[index].displayAttack.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label2)
                                WeLabel(text = "真伤"+nes.weapon[index].trueAttack.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label2)
                            }
                        }
                    }
                    items(nes.defense.size){index->
                        WeSurface(modifier = Modifier.clickable {
                            personAddress.value=index+0x59
                            isSelectDialog.value=false
                        }) {
                            Row(modifier = Modifier
                                .padding(WeTheme.weDp.marginSmall)
                                .fillMaxWidth()
                                .wrapContentHeight()
                                .shadow(
                                    WeTheme.weDp.marginSmall / 2,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .background(
                                    WeTheme.colors.bg,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .padding(WeTheme.weDp.paddingSmall),
                                verticalAlignment = Alignment.CenterVertically,
                                horizontalArrangement = Arrangement.SpaceBetween) {
                                WeLabel(text = (index+nes.weapon.size+1).toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label1)
                                WeLabel(text = nes.defense[index].name, bgColor = WeTheme.colors.label2)
                                WeLabel(text = "价格:"+nes.defense[index].money.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label2)
                                WeLabel(text = "防御:"+nes.defense[index].defense.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label2)
                            }
                        }
                    }
                }
            }
        }
    }
}

@ExperimentalAnimationApi
@Composable
fun SelectProp(personAddress:MutableState<Int>,nes:NesViewModel){
    val isSelectDialog= remember {
        mutableStateOf(false)
    }
    WeButton(text = nes.props[personAddress.value].name, onClick = {
        isSelectDialog.value=true
    })
    if (isSelectDialog.value){
        WeDialog(title = "武器选择", nes = nes, onDismissRequest = {
            isSelectDialog.value=false
        }) {
            Column() {
                WeColumn(){
                    items(nes.props.size){index->
                        WeSurface(modifier = Modifier.clickable {
                            personAddress.value=index
                            isSelectDialog.value=false
                        }) {
                            Row(modifier = Modifier
                                .padding(WeTheme.weDp.marginSmall)
                                .fillMaxWidth()
                                .wrapContentHeight()
                                .shadow(
                                    WeTheme.weDp.marginSmall / 2,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .background(
                                    WeTheme.colors.bg,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .padding(WeTheme.weDp.paddingSmall),
                                verticalAlignment = Alignment.CenterVertically,
                                horizontalArrangement = Arrangement.SpaceBetween) {
                                WeLabel(text = (index+1).toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label1)
                                WeLabel(text = nes.props[index].name, bgColor = WeTheme.colors.label2)
                                WeLabel(text = "价格:"+nes.props[index].money.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label2)
                            }
                        }
                    }
                }
            }
        }
    }
}

@ExperimentalAnimationApi
@Composable
fun SelectWuping(personAddress:MutableState<Int>,nes:NesViewModel){
    val isSelectDialog= remember {
        mutableStateOf(false)
    }
    WeButton(text = if (personAddress.value<13) "无" else if(personAddress.value<0x39) nes.props[personAddress.value].name else if (personAddress.value<0x53) nes.weapon[personAddress.value-0x40].name else nes.defense[personAddress.value-0x59].name, onClick = {
        isSelectDialog.value=true
    })
    if (isSelectDialog.value){
        WeDialog(title = "武器选择", nes = nes, onDismissRequest = {
            isSelectDialog.value=false
        }) {
            Column() {
                WeColumn(){
                    item {
                        WeSurface(modifier = Modifier.clickable {
                            personAddress.value=0
                            isSelectDialog.value=false
                        }) {
                            Row(modifier = Modifier
                                .padding(WeTheme.weDp.marginSmall)
                                .fillMaxWidth()
                                .wrapContentHeight()
                                .shadow(
                                    WeTheme.weDp.marginSmall / 2,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .background(
                                    WeTheme.colors.bg,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .padding(WeTheme.weDp.paddingSmall), verticalAlignment = Alignment.CenterVertically) {
                                WeLabel(text = 0.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label1)
                                Spacer(modifier = Modifier.padding(WeTheme.weDp.paddingMedium))
                                WeLabel(text = "无", bgColor = WeTheme.colors.label2)
                            }
                        }
                    }
                    items(nes.props.size-13){index->
                        WeSurface(modifier = Modifier.clickable {
                            personAddress.value=index+13
                            isSelectDialog.value=false
                        }) {
                            Row(modifier = Modifier
                                .padding(WeTheme.weDp.marginSmall)
                                .fillMaxWidth()
                                .wrapContentHeight()
                                .shadow(
                                    WeTheme.weDp.marginSmall / 2,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .background(
                                    WeTheme.colors.bg,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .padding(WeTheme.weDp.paddingSmall),
                                verticalAlignment = Alignment.CenterVertically,
                                horizontalArrangement = Arrangement.SpaceBetween) {
                                WeLabel(text = (index+1).toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label1)
                                WeLabel(text = nes.props[index+13].name, bgColor = WeTheme.colors.label2)
                                WeLabel(text = "价格:"+nes.props[index+13].money.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label2)
                            }
                        }
                    }
                    items(nes.weapon.size){index->
                        WeSurface(modifier = Modifier.clickable {
                            personAddress.value=index+0x40
                            isSelectDialog.value=false
                        }) {
                            Row(modifier = Modifier
                                .padding(WeTheme.weDp.marginSmall)
                                .fillMaxWidth()
                                .wrapContentHeight()
                                .shadow(
                                    WeTheme.weDp.marginSmall / 2,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .background(
                                    WeTheme.colors.bg,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .padding(WeTheme.weDp.paddingSmall),
                                verticalAlignment = Alignment.CenterVertically,
                                horizontalArrangement = Arrangement.SpaceBetween) {
                                WeLabel(text = (index+nes.props.size-12).toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label1)
                                WeLabel(text = nes.weapon[index].name, bgColor = WeTheme.colors.label2)
                                WeLabel(text = "价格:"+nes.weapon[index].money.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label2)
                                WeLabel(text = "显伤"+nes.weapon[index].displayAttack.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label2)
                                WeLabel(text = "真伤"+nes.weapon[index].trueAttack.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label2)
                            }
                        }
                    }
                    items(nes.defense.size){index->
                        WeSurface(modifier = Modifier.clickable {
                            personAddress.value=index+0x59
                            isSelectDialog.value=false
                        }) {
                            Row(modifier = Modifier
                                .padding(WeTheme.weDp.marginSmall)
                                .fillMaxWidth()
                                .wrapContentHeight()
                                .shadow(
                                    WeTheme.weDp.marginSmall / 2,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .background(
                                    WeTheme.colors.bg,
                                    shape = RoundedCornerShape(WeTheme.weDp.marginSmall)
                                )
                                .padding(WeTheme.weDp.paddingSmall),
                                verticalAlignment = Alignment.CenterVertically,
                                horizontalArrangement = Arrangement.SpaceBetween) {
                                WeLabel(text = (index+nes.weapon.size+nes.props.size-12).toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label1)
                                WeLabel(text = nes.defense[index].name, bgColor = WeTheme.colors.label2)
                                WeLabel(text = "价格:"+nes.defense[index].money.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label2)
                                WeLabel(text = "防御:"+nes.defense[index].defense.toString(if (nes.state.isHex.value) 16 else 10), bgColor = WeTheme.colors.label2)
                            }
                        }
                    }
                }
            }
        }
    }
}